<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		.redDiv{
			width: 200px;
			height: 200px;
			background-color: red;
			float: left;
			margin: 10px;
		}
	</style>
</head>
<body>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
	<div class="redDiv"></div>
</body>
<script type="text/javascript">
	var divs=document.getElementsByTagName("div")
	// 点击div，打印div的下标
	for (var i = 0; i < divs.length; i++) {
		(function(i){
			divs[i].onclick=function(){
				var time=setInterval(function(){
					clearInterval(time);
					console.log(i)
				},500)
			}
		})(i)
	}
</script>
</html>